package com.marchsoft.musicalstore.controller;
import com.marchsoft.musicalstore.entity.SelfTodayClass;
import com.marchsoft.musicalstore.entity.User;
import com.marchsoft.musicalstore.service.StuCourseSer;
import com.marchsoft.musicalstore.util.RequestToJson;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpSession;
import java.util.Date;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 云
 * Date: 2019-11-22
 * Time: 19:36
 */
@RestController
@RequestMapping("/selStuCourse")
public class StuCourseCon {
    @Autowired
    StuCourseSer selStuCourse;

    //通过id获取个人的所有课
    @RequestMapping("/getStuCourse")
    public RequestToJson getClassByTypeLimit(int id){
        List<com.marchsoft.musicalstore.entity.StuCourse> getStuCourse=selStuCourse.getPerCourse(id);
        return new RequestToJson(0,"成功",getStuCourse);
    }

    //通过id和时间查询当天个人课程信息、
//    @RequestMapping("/getPerTodayCourse")
//    public List<StuCourse> getPerTodayCourse(int id){
//        Date d = new Date();
//        System.out.println(d);
//        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//        String dateNowStr = sdf.format(d);
//        System.out.println("格式化后的日期：" + dateNowStr);
//        List <StuCourse> getPerTodayCourse=selStuCourse.getPerTodayCourse(id, (Data) d);
//        return (List<StuCourse>) new RequestToJson(0,"成功",getPerTodayCourse);
//    }

    /**
     * 公共班课的选取
     * @param id
     * @param session
     * @return
     */
    @RequestMapping(value = "/addToComMyCourse",method = RequestMethod.POST)
    public RequestToJson addToComMyCourse(int id, HttpSession session){
        User user = new User();
        user.setId(10);//这是一个测试用户
        session.setAttribute("user",user);
        RequestToJson requestToJson = selStuCourse.addToComMyCourse(id, session);
        return requestToJson;
    }

    /**
     * 源通过时间来获取该用户当天的课程
     * @param time
     * @param week
     * @param session
     */
    @RequestMapping(value = "/getDayClassBytime",method = RequestMethod.GET)
    public void getDayClassBytime(Integer time,Integer week,HttpSession session){
        List dayClassBytime = selStuCourse.getDayClassBytime(time, week, session);
        RequestToJson requestToJson = new RequestToJson(0,"请求成功",dayClassBytime);

    }

    /**
     * 查询学生当天课程
     * @param userId 用户id
     * @param type 班课类型
     * @return
     */
    @RequestMapping(value = "/getPerTodayCourse",method = RequestMethod.GET)
    public RequestToJson getOneClass(int userId,int type){
        Date date = new Date();
        List<SelfTodayClass> todayClass = selStuCourse.getOneClass(userId,date,type);
        RequestToJson requestToJson = new RequestToJson(0,"成功",todayClass);
        return requestToJson;
    }

}
